// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   SongVerse.java

package presenter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Scanner;

public class SongVerse implements Serializable {
    public static final long serialVersionUID=77;
    boolean bibleVerse=false;
    public SongVerse()
    {
        type = "";
    }

    public SongVerse(String[] input)
    {
        if(input[0].length() > 3 && input[0].substring(0, 4).toUpperCase().equals("MISC"))
        {
            String input2[] = new String[input.length - 1];
            for(int i = 1; i < input.length; i++)
                input2[i - 1] = input[i];

            input = input2;
        }
        type = findType(input[0]);
        if(type.equals(""))
        {
            lyrics = input;
        } else
        {
            lyrics = new String[input.length - 1];
            for(int i = 1; i < input.length; i++)
                lyrics[i - 1] = input[i];

        }
    }

    private String findType(String s)
    {
        String temp = s.toUpperCase();
        if(temp.contains("CHORUS"))
        {
            Scanner sc = new Scanner(temp);
            sc.next();
            if(sc.hasNextInt())
                return (new StringBuilder()).append("Chorus ").append(sc.nextInt()).toString();
            else
                return "Chorus";
        }
        if(temp.contains("VERSE"))
        {
            Scanner sc = new Scanner(temp);
            sc.next();
            if(sc.hasNextInt())
                return (new StringBuilder()).append("Verse ").append(temp.substring(6, 7)).toString();
            else
                return "Verse";
        }
        if(temp.contains("BRIDGE"))
            return "Bridge";
        if(temp.contains("ENDING"))
            return "Ending";
        if(temp.contains("PRE-CHORUS"))
            return "Pre-Chorus";
        if(temp.contains("TAG"))
            return "Tag";
        else
            return "";
    }

    public String[] getLyrics()
    {
        return lyrics;
    }

    public String getType()
    {
        return type;
    }

    public String toString()
    {
        String result = "<html> <p style=\"text-align: center;\"> ";
        if(!type.equals(""))
            result = (new StringBuilder()).append(result).append("<b>").append(type).append("</b><br>").toString();
        String[] lyrics=this.lyrics;
        if(!TextInformation.staticFontSize||bibleVerse);
            lyrics=getFormatted(TextInformation.wrapLimit);
        for(int i = 0; i < lyrics.length; i++) {
            result +=lyrics[i].toString();
            result+="<br>";
        }

        result = (new StringBuilder()).append(result).append("<br></p> </html>").toString();
        return result;
    }

    public void setType(String type)
    {
        this.type = type;
    }

    public void setText(String input[])
    {
        lyrics = input;
    }
    
    public String[] getFormatted(int wrapLimit) {
        if(TextInformation.staticFontSize&&!bibleVerse) {
            return lyrics;
        } else {
            ArrayList<String> solution=new ArrayList<String>();
            for(int index=0; index<lyrics.length; index++) {
                if(lyrics[index].length()>=wrapLimit) {
                    String[] s2=split(lyrics[index],wrapLimit);
                    for(int j=0; j<s2.length; j++) {
                        solution.add(s2[j]);
                       // System.out.println(s2[j]);
                    }
                } else {
                    solution.add(lyrics[index]);
                }
            }

            return solution.toArray(new String[0]);
        }
    }
    
    
    private String[] split(String s, int wrapLimit) {
        ArrayList<String> solution= new ArrayList<String>();
        //System.out.println(s);
        //System.out.println(s.length());
        if(s.length()>wrapLimit) {
            int start=s.length()/2;
            for(int i=0; i<s.length()/2; i++) {
                String x=s.substring(start-i,start-i+1);
                String y=s.substring(start+i,start+i+1);
                if(x.equals(" ")) {
                    String temp=s.substring(0,start-i+1);
                    String[] s1=split(temp,wrapLimit);
                    for(int j=0; j<s1.length; j++) 
                        solution.add(s1[j]);
                    temp=s.substring(start-i+1,s.length());
                    String[] s2=split(temp,wrapLimit);
                    for(int j=0; j<s2.length; j++)
                        solution.add(s2[j]);
                    break;
                } else if(y.equals(" ")) {
                    String temp=s.substring(0,start+i+1);
                    String[] s1=split(temp,wrapLimit);
                    for(int j=0; j<s1.length; j++) 
                        solution.add(s1[j]);
                    temp=s.substring(start+i+1,s.length());
                    String[] s2=split(temp,wrapLimit);
                    for(int j=0; j<s2.length; j++)
                        solution.add(s2[j]);
                    break;    
                }
            }
        } else {
            solution.add(s);
        }
            
        return solution.toArray(new String[0]);
    }
 
    String lyrics[];
    String type;
    
    public static void main(String[] args) {
        String[] test={"Where Your streams of abundance flow Blessed be Your name"};
        SongVerse sv=new SongVerse(test);
        test=sv.getFormatted(32);
        for(int i=0; i<test.length; i++) {
           // System.out.println(test[i]);
        }
    }
}
